package com.markyao.aop;

import com.markyao.annotation.RegistKey;
import com.markyao.aop.annotations.WalEnabled;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

@Aspect
@Component
@Slf4j(topic = "m.RecosWalAspect")
public class RecosWalAspect {

    @Pointcut("@annotation(com.markyao.aop.annotations.WalEnabled)")
    public void pj(){}


    @Around("pj()")
    public Object wal(ProceedingJoinPoint pjp) throws Throwable {
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Method method = methodSignature.getMethod();
        WalEnabled walEnabled = method.getAnnotation(WalEnabled.class);
        String logwal = walEnabled.log();
        String value = walEnabled.value();
        log.info("wal: {}  {}",logwal,value);

        Object result = pjp.proceed();
        return result;
    }
}
